home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol04 / 01a / genapp / envrnmt.c < prev    next >
C/C++ Source or Header  |  1988-10-30  |  32KB  |  1,350 lines

  1. void debug();
  2.  
  3. /***************************************************************
  4.     ENVRNMT.C
  5. ****************************************************************/    
  6.  
  7.  
  8. #include "CONFIG.H"
  9.  
  10.  
  11. #ifdef MAC /*----------------MACINTOSH SPECIFIC-----------------*/
  12.  
  13. #include "MacTypes.h"
  14. #include "QuickDraw.h"
  15. #include "WindowMgr.h"
  16. #include "MemoryMgr.h"
  17. #include "EventMgr.h"
  18. #include "MenuMgr.h"
  19. #include "FileMgr.h"
  20. #include "ResourceMgr.h"
  21. #include "StdFilePkg.h"
  22. #include "OSUtil.h"
  23. #include "DialogMgr.h"
  24.  
  25. #include "pascal.h"
  26.  
  27. #else /*---------------------MS_WINDOWS SPECIFIC----------------*/
  28.  
  29. #include "windows.h"
  30.  
  31. #endif /*---------------- END OF WINDOWS SPECIFIC----------------*/
  32.  
  33. #include "STDDEFS.H"
  34. #include "APPLCATN.H"
  35. #include "ENVRNMT.H"
  36.  
  37.  
  38. /****************************************************************/
  39.  
  40. #ifdef MAC
  41. PUBLIC VOID main() /*windows has winMain(). Both call app_Main()*/
  42. {
  43.     app_MainProcedure();
  44. }
  45. #endif
  46.  
  47. /****************************************************************/
  48.  
  49. PUBLIC BOOL env_InitEnvironment()
  50. {
  51. #ifdef MAC
  52.     InitGraf(&thePort);
  53.     InitFonts();
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs((ProcPtr) env_ExitProgram);
  58.     InitCursor();
  59.     FlushEvents( everyEvent, 0 );
  60.         
  61.     MaxApplZone();
  62. #else
  63.     /* MS-Windows environment already initialized by WinMain() */
  64. #endif
  65.     env_InitCanvases();
  66.     return TRUE;
  67. }
  68.  
  69. PUBLIC VOID env_ExitProgram()
  70. {
  71. #ifdef MAC
  72.     ExitToShell();
  73. #endif
  74. }
  75.  
  76. #ifdef MAC
  77. PUBLIC VOID env_FatalError(str,x,y,z)
  78.     STRING str; unsigned x,y,z;
  79. {
  80. #ifdef DBG
  81.     ut_PutString("RV|FatalError: ",str);
  82. #endif
  83.     env_ExitProgram();
  84. }
  85.  
  86. PUBLIC VOID env_NotImplemented(str,x,y,z)
  87.     STRING str; unsigned x,y,z;
  88. {
  89. #ifdef DBG
  90.     ut_PutString("RV|NotImplemented: ",str);
  91. #endif
  92. }
  93. #endif
  94.  
  95. /****************************************************************/
  96.  
  97. PUBLIC BOOL    env_PtInRect(pt, r)
  98.     Point *    pt;
  99.     pRect    r;
  100. {
  101.     return (   pt->v >= r->top  
  102.         && pt->v <  r->bottom 
  103.         && pt->h >= r->left 
  104.         && pt->h <  r->right);
  105. }
  106.  
  107. /****************************************************************/
  108. PUBLIC VOID env_OffsetRect(r, dh, dv)
  109.     Rect *    r;
  110.     int        dh, dv;
  111. {
  112.     r->left   += dh;
  113.     r->right  += dh;
  114.     r->top    += dv;
  115.     r->bottom += dv;
  116. }
  117.  
  118.  
  119. /****************************************************************
  120.     MEMORY ALLOCATION
  121. ****************************************************************/
  122.  
  123.  
  124. PUBLIC MEMBLOCK    env_AllocMem(size)
  125.     MEMSIZE    size;
  126. {
  127. #ifdef MAC
  128.     return (MEMBLOCK) NewHandle((Size) size);
  129. #else
  130.     return GlobalAlloc(GMEM_MOVEABLE, size);
  131. #endif
  132. }
  133.  
  134. PUBLIC VOID        env_ReAllocMem(handle,size)
  135.     MEMBLOCK *    handle;
  136.     MEMSIZE        size;
  137. {
  138. #ifdef MAC
  139.     SetHandleSize((Handle)*handle,(Size)size);
  140. #else
  141. #ifdef AS
  142.     *handle = GlobalReAlloc(*handle,size,GMEM_MOVEABLE);
  143. #else
  144.     HANDLE *h = (HANDLE *)handle;
  145.     *h = GlobalReAlloc(*h,size,GMEM_MOVEABLE);
  146. #endif    
  147. #endif
  148. }
  149.  
  150. PUBLIC MEMPTR env_GraspMem( handle)
  151.     MEMBLOCK    handle;
  152. {
  153. #ifdef MAC
  154.     HLock((Handle)handle);
  155.     return (MEMPTR) *handle;
  156. #else
  157.     return (MEMPTR) GlobalLock(handle);
  158. #endif
  159. }
  160.  
  161. PUBLIC VOID env_UnGraspMem( handle)
  162.     MEMBLOCK    handle;
  163. {
  164. #ifdef MAC
  165.     HUnlock((Handle)handle);
  166. #else
  167.     GlobalUnlock(handle);
  168. #endif
  169. }
  170.  
  171. PUBLIC VOID env_FreeMem(handle)
  172.     MEMBLOCK    handle;
  173. {
  174. #ifdef MAC
  175.     DisposHandle((Handle)handle);
  176. #else
  177.     GlobalFree(handle);
  178. #endif
  179. }
  180.  
  181. #ifdef NOT_IMPLEMENTED
  182. PUBLIC MEMSIZE env_GetMemblkSize() {;}
  183. #endif
  184.  
  185. /****************************************************************
  186.     OPERATIONS ON WINDOWS
  187. ****************************************************************/
  188.  
  189. #include "view.h"
  190.  
  191. #ifndef MAC
  192. PUBLIC BOOL window_is_being_created; /*flag for critical section*/
  193. #endif
  194.  
  195. PUBLIC BOOL env_NewWindow(title, bounds, vu, canvas)
  196.  
  197.     STRING        title;
  198.     Rect *        bounds;
  199.     INDEX        vu,canvas;
  200. {
  201. #ifdef MAC
  202. #define SIZEOF_STR 128
  203.      WindowPtr    wPtr;
  204.      char str[SIZEOF_STR];
  205.     
  206.     ut_PrintMacRect("RV|envNewWindow: rect",bounds);
  207.     
  208.     if(strlen(title) >= SIZEOF_STR) title[SIZEOF_STR-1] = '\0';
  209.     strcpy(str,title);
  210.              
  211.     wPtr = NewWindow( (WindowPtr) env_GetAddrDevBlock(canvas), 
  212.                     bounds,
  213.                     CtoPstr(str),
  214.                     TRUE /*visible*/,
  215.                     documentProc /*standard window type*/,
  216.                     (WindowPtr) -1 /*front-most window*/,
  217.                     TRUE /*go-away*/,
  218.                     (long) vu /*refcon field*/
  219.                     );
  220.                     
  221.     ut_PrintHex("RV|NewWindow returns wptr",(long)wPtr);
  222.     if(wPtr==(WindowPtr)NULL) return FALSE;
  223.  
  224.     env_SetCanvasDev(canvas,(long)wPtr);
  225.     env_CalcSizeCanvas(canvas);
  226.     return TRUE;
  227. #else
  228.     IMPORT HANDLE win_GethAppInstance();
  229.     IMPORT HWND   win_GethAppWnd();
  230.     HWND    hWnd;
  231.  
  232.     ut_PrintMacRect("RV|envNewWindow: rect",bounds);
  233.     ut_Print2Hex("RV|envNewWindow: hAppInst, hAppWnd",
  234.         (long)win_GethAppInstance(),(long)win_GethAppWnd());
  235.         
  236.     window_is_being_created = TRUE;
  237.     
  238.     hWnd = CreateWindow(
  239.             (LPSTR) "Child",
  240.         (LPSTR) title,
  241.         WS_CHILD 
  242.             | WS_CAPTION 
  243.             | WS_SYSMENU 
  244.             | WS_SIZEBOX 
  245.             | WS_CLIPSIBLINGS
  246.             | WS_VISIBLE
  247.             | WS_BORDER,
  248.         bounds->left, bounds->top,
  249.         (bounds->right  - bounds->left),
  250.         (bounds->bottom - bounds->top ),
  251.         win_GethAppWnd(),
  252.         (HMENU)NULL,
  253.         win_GethAppInstance(),
  254.         (LPSTR) NULL
  255.     );
  256.  
  257.     ut_PrintHex("RV|CreateWindow returns hWnd",(long)hWnd);
  258.     if(hWnd==(HWND)NULL) return FALSE;
  259.  
  260.     env_SetCanvasDev(canvas,(long)hWnd);
  261.     SetWindowWord(hWnd, 0, canvas);
  262.     window_is_being_created = FALSE;
  263.     
  264.     ShowWindow(hWnd, SHOW_OPENWINDOW);
  265.     env_CalcSizeCanvas(canvas);
  266.     /*>>BringWindowToTop(hWnd);*/
  267.     /*>>UdateWindow(hWnd);*/
  268.     return TRUE;
  269. #endif
  270. }
  271.  
  272.  
  273.  
  274. PUBLIC VOID env_GetScreenSize(rect)
  275.     Rect *rect;
  276. {
  277. #ifdef MAC
  278.     GrafPtr    theWMgrPort;
  279.     /*assumes that InitWindows() has been called*/
  280.     GetWMgrPort( &theWMgrPort);
  281.     *rect = theWMgrPort->portRect; /*structure copy */
  282. #else
  283.     IMPORT VOID win_UpdateAppWndSize();
  284.     win_UpdateAppWndSize(rect);
  285. #endif
  286. }
  287.  
  288. /****************************************************************
  289.     GRAPHICS DRAWING
  290. ****************************************************************/
  291.  
  292. #ifndef MAC
  293.  
  294. LOCAL VOID select_fill_pattern(hDC,pattern) 
  295.     HDC hDC; PATT pattern;
  296. {
  297.     switch (pattern)
  298.     {
  299.     case PATT_WHITE:
  300.         DeleteObject(SelectObject(hDC,GetStockObject(WHITE_BRUSH)));break;
  301.     case PATT_BLACK:
  302.         DeleteObject(SelectObject(hDC,GetStockObject(BLACK_BRUSH)));break;
  303.     case PATT_GRAY:
  304.         DeleteObject(SelectObject(hDC,GetStockObject(GRAY_BRUSH))); break;
  305.     case PATT_LTGRAY:
  306.         DeleteObject(SelectObject(hDC,GetStockObject(LTGRAY_BRUSH)));break;
  307.     case PATT_DKGRAY:
  308.         DeleteObject(SelectObject(hDC,GetStockObject(DKGRAY_BRUSH))); break;
  309.     case PATT_FWD:
  310.     case PATT_BACK:
  311.     case PATT_HORL:
  312.     case PATT_VERT:
  313.     case PATT_VERTX:
  314.     case PATT_DIAGX:
  315.     case PATT_NULLPA:
  316.     case PATT_DOT:
  317.     case PATT_DASH:
  318.     case PATT_DASHDO:
  319.     case PATT_DASHDD:
  320.         DeleteObject(SelectObject(hDC,GetStockObject(GRAY_BRUSH))); break;
  321.     }
  322. }        
  323.  
  324.  
  325. LOCAL VOID null_brush(hDC) HDC hDC;
  326. {
  327.     DeleteObject( SelectObject( hDC, GetStockObject(NULL_BRUSH) ) );
  328. }
  329.  
  330. LOCAL VOID null_pen(hDC) HDC hDC;
  331. {
  332.     DeleteObject( SelectObject( hDC, GetStockObject(NULL_PEN) ) );
  333. }
  334.  
  335. #endif
  336.  
  337.  
  338.  
  339. /****************************************************************/
  340.     
  341. typedef struct 
  342. {
  343.     long            userdata;
  344.     short            right, bottom;
  345.     short            x,y;
  346. #ifdef MAC
  347.     GrafPtr            grafptr;
  348.     WindowRecord     wRecord;
  349.     short            scale;
  350. #else
  351.     PAINTSTRUCT        ps;
  352.     HWND            hWnd;
  353.     Rect            winRect; /*entire window*/
  354.     Rect            portRect; /*client area*/
  355.     Rect            scrBounds; /*position of screen relative to win*/
  356. #endif
  357. } CANVAS;
  358.  
  359. /* macros to simplify access to the environment block */
  360.  
  361. #ifdef MAC
  362. #define SCROLL_BAR_WIDTH    16
  363.  
  364. #define CANVAS_GP(hCanvas)        (theSetOfCanvases[hCanvas].grafptr)
  365. #define CANVAS_WP(hCanvas)        ((WindowPtr)(theSetOfCanvases[hCanvas].grafptr))
  366. #define CANVAS_WREC(hCanvas)    (theSetOfCanvases[hCanvas].wRecord)
  367. #define CANVAS_SCALE(hCanvas)    (theSetOfCanvases[hCanvas].scale)
  368. #define CANVAS_PORTRECT(hCanvas) (CANVAS_WP(hCanvas)->portRect)
  369. #else
  370. #define CANVAS_PS(hCanvas)        (theSetOfCanvases[hCanvas].ps)
  371. #define CANVAS_HDC(hCanvas)        (CANVAS_PS(hCanvas).hdc)
  372. #define CANVAS_HWND(hCanvas)    (theSetOfCanvases[hCanvas].hWnd)
  373. #define CANVAS_PORTRECT(hCanvas) (theSetOfCanvases[hCanvas].portRect)
  374. #endif
  375.  
  376. #define CANVAS_USERDATA(hCanvas) (theSetOfCanvases[hCanvas].userdata)
  377.  
  378. #define CANVAS_RIGHT(hCanvas)    (theSetOfCanvases[hCanvas].right)
  379. #define CANVAS_BOTTOM(hCanvas)    (theSetOfCanvases[hCanvas].bottom)
  380. #define CANVAS_X(hCanvas)        (theSetOfCanvases[hCanvas].x)
  381. #define CANVAS_Y(hCanvas)        (theSetOfCanvases[hCanvas].y)
  382.     
  383. #define NUM_CANVAS_BLOCKS        10    
  384.  
  385. #define ILLEGAL_USERDATA    ((long)-1)
  386.  
  387. LOCAL CANVAS theSetOfCanvases[NUM_CANVAS_BLOCKS] = {0};
  388.  
  389. #ifdef MAC
  390.  
  391. /* the first macro takes one argument, 
  392.  * the second macro takes two args.
  393.  */
  394.  
  395. #define SWITCH_PORT(gp,func,rect)    \
  396. {                                    \
  397.     GrafPtr oldport = thePort;        \
  398.     SetPort(gp);                    \
  399.     func(rect);                        \
  400.     SetPort(oldport);                \
  401. }
  402.  
  403. #define SWITCH_PORT_XY(gp,func,x,y)    \
  404. {                                    \
  405.     GrafPtr oldport = thePort;        \
  406.     SetPort(gp);                    \
  407.     func(x,y);                        \
  408.     SetPort(oldport);                \
  409. }
  410. #endif
  411.  
  412. /**********************************************************************/
  413. LOCAL VOID env_IsCanvasValid(hCanvas)
  414.     HCANVAS hCanvas;
  415. {
  416.     if (hCanvas >= NUM_CANVAS_BLOCKS)
  417.         env_FatalError("No such hCanvas: %u", hCanvas);
  418. #ifndef MAC
  419.     /* Windows lets us do a little more error checking */
  420.     if (! IsWindow(CANVAS_HWND(hCanvas)))
  421.         env_FatalError("Illegal hWnd %u in hCanvas %u", 
  422.                 CANVAS_HWND(hCanvas), hCanvas);
  423. #endif
  424. }
  425.  
  426. /**********************************************************************/
  427.  
  428.  
  429. PUBLIC VOID env_InitCanvases()
  430. {
  431.     register HCANVAS hCanvas;
  432.     for (hCanvas=0; hCanvas < NUM_CANVAS_BLOCKS; hCanvas++)
  433.         CANVAS_USERDATA(hCanvas) = ILLEGAL_USERDATA;
  434. }
  435.  
  436. PUBLIC HCANVAS env_NewCanvas(userdata)
  437.     LONG    userdata;
  438. {
  439.     register HCANVAS hCanvas;
  440.     for (hCanvas=0; hCanvas < NUM_CANVAS_BLOCKS; hCanvas++)
  441.     {
  442.         if (CANVAS_USERDATA(hCanvas)==ILLEGAL_USERDATA)
  443.         {
  444.             CANVAS_USERDATA(hCanvas) = userdata;
  445.             return hCanvas;
  446.         }
  447.     }
  448.     /* still here */
  449.     return INVALID_INDEX;
  450. }
  451.  
  452. #ifdef MAC
  453. PUBLIC BOOL env_IsDevData(devdata)
  454.     LONG devdata;
  455. {
  456.     register HCANVAS hCanvas;
  457.     for (hCanvas=0; hCanvas < NUM_CANVAS_BLOCKS; hCanvas++)
  458.         if(CANVAS_USERDATA(hCanvas) != ILLEGAL_USERDATA
  459.             && devdata==(long)CANVAS_GP(hCanvas))
  460.                 return TRUE;
  461.     /*else*/
  462.     return FALSE;
  463. }
  464.  
  465. PUBLIC MEMPTR env_GetAddrDevBlock(hCanvas)
  466.     HCANVAS    hCanvas;
  467. {
  468.     env_IsCanvasValid(hCanvas);
  469.     return (MEMPTR) &CANVAS_WREC(hCanvas);
  470. }
  471. #endif
  472.  
  473. #if 0
  474.  
  475. PUBLIC HCANVAS env_FindCanvas(hWnd)
  476.     HWND hWnd;
  477. {
  478.     register HCANVAS hCanvas;
  479.     for (hCanvas=0; hCanvas < NUM_CANVAS_BLOCKS; hCanvas++)
  480.         if (CANVAS_HWND(hCanvas) == hWnd)
  481.             return hCanvas;
  482.     /* still here:  create an env for them */
  483.     return env_NewCanvas(hWnd);
  484. }
  485. #endif
  486.  
  487. /**********************************************************************/
  488.  
  489. PUBLIC VOID env_FreeCanvas(hCanvas)
  490.     HCANVAS hCanvas;
  491. {
  492.     env_IsCanvasValid(hCanvas);
  493.     /* set all fields to zero */
  494.     memset((MEMPTR)&theSetOfCanvases[hCanvas], 0, sizeof(CANVAS));
  495.     CANVAS_USERDATA(hCanvas) = ILLEGAL_USERDATA;
  496. }
  497.  
  498. /**********************************************************************/
  499.  
  500. PUBLIC VOID env_ActivateCanvas(hCanvas)
  501.     HCANVAS hCanvas;
  502. {
  503. #ifdef MAC
  504. #else
  505.     env_IsCanvasValid(hCanvas);
  506.     BringWindowToTop( CANVAS_HWND(hCanvas) );
  507. #endif
  508. }
  509.  
  510. PUBLIC VOID env_InvalidateCanvas(hCanvas, rect)
  511.     HCANVAS hCanvas;
  512.     Rect *    rect;
  513. {
  514. #ifdef MAC
  515.     GrafPtr    savePort;
  516.     env_IsCanvasValid(hCanvas);
  517.     GetPort( &savePort );
  518.     SetPort( CANVAS_GP(hCanvas) );
  519.     InvalRect( &(CANVAS_PORTRECT(hCanvas)));
  520.     SetPort( savePort);
  521. #else
  522.     env_IsCanvasValid(hCanvas);
  523.     if(rect==(Rect *)NULL)
  524.         InvalidateRect(CANVAS_HWND(hCanvas),(LPRECT)NULL,(BOOL)TRUE);
  525.     else
  526.         env_FatalError("InvalidateCanvas: not impl!");
  527. #endif
  528.  
  529. }
  530.  
  531. /**********************************************************************/
  532. #ifdef MAC
  533. LOCAL GrafPtr    saved_port;
  534. #endif
  535.  
  536. PUBLIC VOID env_StartDrawing(hCanvas)
  537.     HCANVAS    hCanvas;
  538. {
  539. #ifdef MAC
  540.     env_IsCanvasValid(hCanvas);
  541.     GetPort( &saved_port );
  542.     SetPort( CANVAS_GP(hCanvas) );
  543. #else
  544.     env_IsCanvasValid(hCanvas);
  545.     CANVAS_HDC(hCanvas) = GetDC(CANVAS_HWND(hCanvas));
  546. #endif
  547. }
  548.  
  549. PUBLIC VOID env_EndDrawing(hCanvas)
  550.     HCANVAS    hCanvas;
  551. {
  552. #ifdef MAC
  553.     SetPort(saved_port);
  554.     saved_port = (GrafPtr)0;
  555. #else
  556.     env_IsCanvasValid(hCanvas);
  557.     ReleaseDC( CANVAS_HWND(hCanvas), CANVAS_HDC(hCanvas));
  558.     CANVAS_HDC(hCanvas) = 0;
  559. #endif
  560. }
  561.  
  562. /**********************************************************************/
  563.  
  564. PUBLIC VOID env_SetCanvasDev(hCanvas, devdata)
  565.     HCANVAS    hCanvas;
  566.     LONG    devdata;
  567. {
  568. #ifdef MAC
  569.     env_IsCanvasValid(hCanvas);
  570.     CANVAS_GP(hCanvas) = (GrafPtr) devdata;
  571. #else
  572.     /*env_IsCanvasValid(hCanvas);<<<is not yet valid<<<*/
  573.     CANVAS_HWND(hCanvas) = LOWORD(devdata);
  574.     ut_PrintHex("RV|SetCanvasDev: hWnd=",(LONG) CANVAS_HWND(hCanvas));
  575. #endif
  576. }
  577.  
  578. PUBLIC LONG env_GetCanvasDev(hCanvas)
  579.     HCANVAS    hCanvas;
  580. {
  581. #ifdef MAC
  582.     env_IsCanvasValid(hCanvas);
  583.     return (LONG) CANVAS_GP(hCanvas);
  584. #else
  585.     env_IsCanvasValid(hCanvas);
  586.     return (LONG) CANVAS_HWND(hCanvas);
  587. #endif
  588. }
  589.  
  590. /**********************************************************************
  591.     GRAPHICS PRIMITIVES
  592. /*********************************************************************/
  593.  
  594. PUBLIC VOID env_TextOut(hCanvas, x, y, str)
  595.     HCANVAS hCanvas;
  596.     PIXEL    x,y;
  597.     STRING    str;
  598. {
  599. #ifdef MAC
  600.     env_MoveTo(hCanvas, x, y);
  601.     DrawText((Ptr) str, 0, strlen(str));
  602. #else
  603.     /*need to add windows code */
  604. #endif
  605. }
  606.  
  607.  
  608.  
  609. PUBLIC VOID env_MoveRel(hCanvas, x, y)
  610.     HCANVAS hCanvas;
  611.     short x,y;
  612. {
  613. #ifdef MAC
  614.     env_IsCanvasValid(hCanvas);
  615.     
  616.     x *= CANVAS_SCALE(hCanvas);
  617.     y *= CANVAS_SCALE(hCanvas);
  618.  
  619.     if (CANVAS_GP(hCanvas) != thePort)
  620.         SWITCH_PORT_XY(CANVAS_GP(hCanvas),Move,x,y)
  621.     else
  622.         Move(x,y);
  623. #else
  624.     env_IsCanvasValid(hCanvas);
  625.             
  626.     CANVAS_X(hCanvas) += x;
  627.     CANVAS_Y(hCanvas) += y;
  628.     MoveTo(CANVAS_HDC(hCanvas), CANVAS_X(hCanvas), CANVAS_Y(hCanvas));
  629. #endif
  630. }
  631.  
  632. PUBLIC VOID env_Line(hCanvas, x, y)
  633.     HCANVAS hCanvas;
  634.     short x,y;
  635. {
  636. #ifdef MAC
  637.     env_IsCanvasValid(hCanvas);
  638.  
  639.     x *= CANVAS_SCALE(hCanvas);
  640.     y *= CANVAS_SCALE(hCanvas);
  641.  
  642.     if (CANVAS_GP(hCanvas) != thePort)
  643.         SWITCH_PORT_XY(CANVAS_GP(hCanvas),Line,x,y)
  644.     else
  645.         Line(x,y);
  646. #else
  647.     env_IsCanvasValid(hCanvas);
  648.     CANVAS_X(hCanvas) += x;
  649.     CANVAS_Y(hCanvas) += y;
  650.     LineTo(CANVAS_HDC(hCanvas), CANVAS_X(hCanvas), CANVAS_Y(hCanvas));
  651. #endif
  652. }
  653.  
  654. PUBLIC VOID env_MoveTo(hCanvas, x, y)
  655.     HCANVAS hCanvas;
  656.     short x,y;
  657. {
  658. #ifdef MAC
  659.     env_IsCanvasValid(hCanvas);
  660.  
  661.     x *= CANVAS_SCALE(hCanvas);
  662.     y *= CANVAS_SCALE(hCanvas);
  663.  
  664.     if (CANVAS_GP(hCanvas) != thePort)
  665.         SWITCH_PORT_XY(CANVAS_GP(hCanvas),Line,x,y)
  666.     else
  667.         MoveTo(x,y);
  668. #else
  669.     env_IsCanvasValid(hCanvas);
  670.     CANVAS_X(hCanvas) = x;
  671.     CANVAS_Y(hCanvas) = y;
  672.     MoveTo(CANVAS_HDC(hCanvas), CANVAS_X(hCanvas), CANVAS_Y(hCanvas));
  673. #endif
  674. }
  675.  
  676. PUBLIC VOID env_LineTo(hCanvas, x, y)
  677.     HCANVAS hCanvas;
  678.     short x,y;
  679. {
  680. #ifdef MAC
  681.     env_IsCanvasValid(hCanvas);
  682.  
  683.     x *= CANVAS_SCALE(hCanvas);
  684.     y *= CANVAS_SCALE(hCanvas);
  685.  
  686.     if (CANVAS_GP(hCanvas) != thePort)
  687.         SWITCH_PORT_XY(CANVAS_GP(hCanvas),Line,x,y)
  688.     else
  689.         LineTo(x,y);
  690. #else
  691.     env_IsCanvasValid(hCanvas);
  692.     CANVAS_X(hCanvas) = x;
  693.     CANVAS_Y(hCanvas) = y;
  694.     LineTo(CANVAS_HDC(hCanvas), CANVAS_X(hCanvas), CANVAS_Y(hCanvas));
  695. #endif
  696. }
  697.  
  698.  
  699. PUBLIC VOID env_PaintRect(hCanvas, r)
  700.     HCANVAS hCanvas;
  701.     Rect *    r;
  702. {
  703. #ifdef MAC
  704.     env_IsCanvasValid(hCanvas);
  705.     if (CANVAS_GP(hCanvas) != thePort)
  706.         SWITCH_PORT(CANVAS_GP(hCanvas),PaintRect,r)
  707.     else
  708.         PaintRect(r);
  709. #else
  710.     env_IsCanvasValid(hCanvas);
  711.     null_pen(CANVAS_HDC(hCanvas));
  712.     Rectangle(CANVAS_HDC(hCanvas), r->left, r->top, r->right, r->bottom);
  713. #endif
  714. }
  715.  
  716. PUBLIC VOID env_FrameRect(hCanvas, r)
  717.     HCANVAS hCanvas;
  718.     Rect *    r;
  719. {
  720. #ifdef MAC
  721.     env_IsCanvasValid(hCanvas);
  722.     if (CANVAS_GP(hCanvas) != thePort)
  723.         SWITCH_PORT(CANVAS_GP(hCanvas),FrameRect,r)
  724.     else
  725.         FrameRect(r);
  726. #else
  727.     ut_PrintMacRect("RV|envFrameRect: r",r);
  728.     env_IsCanvasValid(hCanvas);
  729.     null_brush(CANVAS_HDC(hCanvas));
  730.     Rectangle(CANVAS_HDC(hCanvas), r->left, r->top, r->right, r->bottom);
  731. #endif
  732. }
  733.  
  734.  
  735. PUBLIC VOID env_FillRect(hCanvas, r, pat)
  736.     HCANVAS hCanvas;
  737.     Rect *r;
  738.     PATT pat;
  739. {
  740. #ifdef MAC
  741.     /*need to add mac equivalent*/
  742. #else
  743.     env_IsCanvasValid(hCanvas);
  744.     /* do without Windows FillRect() function */    
  745.     select_fill_pattern(CANVAS_HDC(hCanvas),pat);
  746.     SetROP2(CANVAS_HDC(hCanvas), R2_COPYPEN);
  747.     Rectangle(CANVAS_HDC(hCanvas),r->left,r->top,r->right,r->bottom);
  748. #endif
  749. }
  750.  
  751.  
  752. #if 0
  753. PUBLIC VOID env_GetXY(hCanvas, x, y)
  754.     HCANVAS hCanvas;
  755.     short *x, *y;
  756. {
  757. #ifdef MAC
  758.     env_IsCanvasValid(hCanvas);
  759.     *x = CANVAS_GP(hCanvas)->pnLoc.h * CANVAS_SCALE(hCanvas);
  760.     *y = CANVAS_GP(hCanvas)->pnLoc.v * CANVAS_SCALE(hCanvas);
  761. #else
  762.     env_IsCanvasValid(hCanvas);
  763.     *x = CANVAS_X(hCanvas);
  764.     *y = CANVAS_Y(hCanvas);
  765. #endif
  766. }
  767.  
  768. PUBLIC VOID env_GetSizeCanvas(hCanvas, x, y)
  769.     HCANVAS hCanvas;
  770.     short *x, *y;
  771. {
  772. #ifdef MAC
  773.     Rect r;
  774.     env_IsCanvasValid(hCanvas);
  775.     r = CANVAS_GP(hCanvas)->portRect;        /* structure copy */
  776.     *x = (r.right - r.left) - SCROLL_BAR_WIDTH;
  777.     *y = (r.bottom - r.top) - SCROLL_BAR_WIDTH;
  778. #else
  779.     env_IsCanvasValid(hCanvas);
  780.     *x = CANVAS_RIGHT(hCanvas);
  781.     *y = CANVAS_BOTTOM(hCanvas);
  782. #endif
  783. }
  784. #endif
  785.  
  786.  
  787. /***********************************************************************/
  788.  
  789. PUBLIC VOID env_ResizeCanvas(hCanvas,where)
  790.     HCANVAS hCanvas; Point *where;
  791. {
  792. #ifdef MAC
  793.     long        new_size;
  794.     Rect        r;
  795.     Point        pt;
  796.     pt = *where; /*structure copy*/
  797.     env_IsCanvasValid(hCanvas);
  798.     env_GetScreenSize(&r);
  799.     new_size = GrowWindow( CANVAS_GP(hCanvas), pt, &r);
  800.     SizeWindow( CANVAS_GP(hCanvas), LoWord(new_size), HiWord(new_size), TRUE);
  801.     
  802.     /*should do inval rect for just the scroll bars */
  803.     InvalRect( &(CANVAS_GP(hCanvas)->portRect));
  804. #endif
  805. }
  806.  
  807. /***********************************************************************/
  808.  
  809. PUBLIC VOID env_MoveCanvas(hCanvas,where)
  810.     HCANVAS hCanvas; Point *where;
  811. {
  812. #ifdef MAC
  813.     Rect        r;
  814.     Point        pt;
  815.     env_GetScreenSize(&r);
  816.     pt = *where; /*structure copy*/
  817.     DragWindow( CANVAS_GP(hCanvas), pt, &r );
  818. #else
  819.     /*not needed in MS Windows*/
  820. #endif
  821. }
  822.  
  823. /****************************************************************/
  824.  
  825. PUBLIC VOID env_CalcSizeCanvas(hCanvas)
  826.     HCANVAS hCanvas;
  827. {
  828. #ifdef MAC /*Not Needed on mac*/
  829.     env_IsCanvasValid(hCanvas);
  830. #else
  831.     IMPORT VOID win_GetAppWndRect(),win_ScreenToAppl();
  832.     HWND        hWnd;
  833.     RECT        ms_rect,r;
  834.     HDC        hDC;
  835.     long        window_origin;
  836.     POINT        origin_pt,p1,p2;
  837.     CANVAS *    canvas;
  838.     
  839.     env_IsCanvasValid(hCanvas);
  840.  
  841. #ifdef AS
  842.     /* WHAT'S THIS canvas->hWnd STUFF???? */
  843. #endif
  844.     canvas = &(theSetOfCanvases[hCanvas]);
  845.     hDC = CANVAS_HDC(hCanvas);
  846.  
  847.     /* get entire extent of current window in SCREEN coordinates */
  848.     GetWindowRect(canvas->hWnd, (LPRECT) &(canvas->winRect));
  849.     
  850.     ut_Print4Shorts("RV|envResizeCanvas: winRect PHYS",
  851.         canvas->winRect.left,  canvas->winRect.top, 
  852.         canvas->winRect.right, canvas->winRect.bottom);
  853.  
  854.     /* convert window extent to APPLICATION coordinates, 
  855.      * i.e., Mac "Global" coords
  856.          */
  857.  
  858.     p1.x = canvas->winRect.left;  
  859.     p1.y = canvas->winRect.top;        win_ScreenToAppl(&p1);
  860.     p2.x = canvas->winRect.right;
  861.     p2.y = canvas->winRect.bottom;    win_ScreenToAppl(&p2);
  862.  
  863.     ut_Print4Shorts("RV|envResizeCanvas: W in APPL coords",
  864.             p1.x,p1.y,p2.x,p2.y);
  865.  
  866.     canvas->winRect.left   = p1.x;    canvas->winRect.top    = p1.y;
  867.     canvas->winRect.right  = p2.x;    canvas->winRect.bottom = p2.y;    
  868.  
  869.     GetClientRect(canvas->hWnd, (LPRECT) &ms_rect);
  870.  
  871.     p1.x = ms_rect.left;    p1.y = ms_rect.top;
  872.     p2.x = ms_rect.right;    p2.y = ms_rect.bottom;
  873.  
  874.     ClientToScreen(canvas->hWnd, (LPPOINT)&p1); win_ScreenToAppl(&p1);
  875.     ClientToScreen(canvas->hWnd, (LPPOINT)&p2); win_ScreenToAppl(&p2);
  876.     
  877.     canvas->portRect.left   = 0;    
  878.     canvas->portRect.top    = 0; 
  879.     canvas->portRect.right  = (p2.x - p1.x);
  880.     canvas->portRect.bottom = (p2.y - p1.y);
  881.     
  882. #ifdef AS
  883.     /* right now, hDC is zero! */
  884.     env_OffsetRect(&(canvas->portRect), 0, 0);
  885. #else
  886.     window_origin = GetWindowOrg(hDC);
  887.  
  888.     origin_pt  = MAKEPOINT(window_origin);
  889.     
  890.     env_OffsetRect(&(canvas->portRect), origin_pt.x, origin_pt.y);
  891. #endif    
  892.     
  893.     win_GetAppWndRect(&r);            
  894.  
  895.     canvas->scrBounds.left   = r.left   + canvas->portRect.left  - p1.x;
  896.     canvas->scrBounds.top    = r.top    + canvas->portRect.top   - p1.y;
  897.     canvas->scrBounds.right  = r.right  + canvas->portRect.left  - p1.x;
  898.     canvas->scrBounds.bottom = r.bottom + canvas->portRect.top   - p1.y;
  899.  
  900.     ut_PrintMacRect("RV|envResizeCanvas: pBbounds WITH org",
  901.         &(canvas->scrBounds));
  902. #endif
  903. }
  904.  
  905. /****************************************************************/
  906.  
  907. PUBLIC VOID    env_GlobalToLocal(hCanvas,pt)
  908.     HCANVAS    hCanvas;
  909.     Point *    pt;    
  910. {
  911. #ifdef MAC
  912.     env_IsCanvasValid(hCanvas);
  913.     if (CANVAS_GP(hCanvas) != thePort)
  914.         SWITCH_PORT(CANVAS_GP(hCanvas),GlobalToLocal,pt)
  915.     else
  916.         GlobalToLocal(pt);
  917. #else
  918.     CANVAS *    canvas;
  919.     
  920.     env_IsCanvasValid(hCanvas);
  921.  
  922.     canvas = &(theSetOfCanvases[hCanvas]);
  923.  
  924.     ut_Print2Shorts("RV|GlobalToLocal: p GLOBAL",pt->h,pt->v);
  925.     ut_PrintMacRect("RV|GlobalToLocal: scrBnds ",&(canvas->scrBounds));
  926.  
  927.     pt->h += canvas->scrBounds.left;
  928.     pt->v += canvas->scrBounds.top;
  929.     ut_Print2Shorts("RV|GlobalToLocal: p LOCAL",pt->h,pt->v);
  930. #endif
  931. }
  932.  
  933. /****************************************************************/
  934.  
  935. PUBLIC VOID env_OffsetOrgCanvas(hCanvas, x, y)
  936.     HCANVAS hCanvas;
  937.     short x, y;
  938. {
  939. #if 0
  940.     env_IsCanvasValid(hCanvas);
  941.     OffsetViewportOrg(CANVAS_HDC(hCanvas), x, y);
  942.     /* Mac hCanvas will need to keep around old origin? */
  943. #endif
  944. }
  945.  
  946. PUBLIC VOID env_SetScaleCanvas(hCanvas, x, y, units)
  947.     HCANVAS hCanvas;
  948.     short x, y, units;
  949. {
  950. #ifdef MAC
  951.     env_IsCanvasValid(hCanvas);
  952.     CANVAS_SCALE(hCanvas) = min(x,y) / units;
  953. #else
  954.     env_IsCanvasValid(hCanvas);
  955.     SetMapMode(CANVAS_HDC(hCanvas), MM_ISOTROPIC);
  956.     SetWindowExt(CANVAS_HDC(hCanvas), units, units);
  957.     SetViewportExt(CANVAS_HDC(hCanvas), x, y);
  958. #endif
  959. }
  960.  
  961. /**********************************************************************/
  962.  
  963. PUBLIC VOID env_BeginUpdate(hCanvas)
  964.     HCANVAS hCanvas;
  965. {
  966. #ifdef MAC
  967.     env_IsCanvasValid(hCanvas);
  968.     
  969.     /*rect = (**((GrafPtr)canvas)->visRgn).rgnBBox; structure copy 
  970.     EraseRect( &(canvas->portRect));*/
  971.         
  972.     BeginUpdate(CANVAS_WP(hCanvas));
  973. #else
  974.     env_IsCanvasValid(hCanvas);
  975.     BeginPaint(CANVAS_HWND(hCanvas), &CANVAS_PS(hCanvas));
  976. #endif
  977. }
  978.  
  979. PUBLIC VOID env_EndUpdate(hCanvas)
  980.     HCANVAS hCanvas;
  981. {
  982. #ifdef MAC
  983.     env_IsCanvasValid(hCanvas);
  984.     EndUpdate(CANVAS_WP(hCanvas));
  985.     DrawGrowIcon( CANVAS_WP(hCanvas));
  986. #else
  987.     env_IsCanvasValid(hCanvas);
  988.     EndPaint(CANVAS_HWND(hCanvas), &CANVAS_PS(hCanvas));
  989.     CANVAS_HDC(hCanvas) = 0;
  990. #endif
  991. }
  992.  
  993.  
  994. /****************************************************************
  995.     EVENT PROCESSING
  996. ****************************************************************/
  997.  
  998. PUBLIC VOID env_GetAppEvent(appEvent)
  999.     APPEVENT *        appEvent;
  1000. {
  1001. #ifdef MAC
  1002.     IMPORT BOOL mac_EventLoop();
  1003.     /* inner event loop handles system and internal events*/
  1004.     while( mac_EventLoop(appEvent))
  1005.         /*continue*/; 
  1006. #else
  1007.     IMPORT VOID win_GetAppEvent();
  1008.     win_GetAppEvent(appEvent);
  1009. #endif
  1010. }
  1011.  
  1012. /****************************************************************
  1013.     MACINTOSH SPECIFIC EVENT HANDLING (Internal Event Loop)
  1014. ****************************************************************/    
  1015. #ifdef MAC
  1016.  
  1017. #include "EventMgr.h"
  1018.  
  1019. #ifdef DBG /*for debugging*/
  1020. LOCAL STRING event_types[] =
  1021. {
  1022.     "nullEvent","mouseDown","mouseUp","keyDown",
  1023.     "keyUp","autoKey","updateEvt","diskEvt",
  1024.     "activateEvt","event 9","networkEvt","driverEvt",
  1025.     "app1Evt","app2Evt","app3Evt","app4Evt"
  1026. };
  1027.  
  1028. LOCAL STRING mousedown_types[] =
  1029. {
  1030.     "inDesk","inMenuBar","inSysWindow","inContent",
  1031.     "inDrag","inGrow","inGoAway","inZoomIn","inZoomOut"
  1032. };
  1033. #endif
  1034.  
  1035.  
  1036. LOCAL BOOL mac_EventLoop(appEvent)
  1037.     APPEVENT *        appEvent;
  1038. {
  1039.     EventRecord        macEvent;
  1040.     WindowPtr        whichWindow;
  1041.     
  1042.     SystemTask();
  1043.     
  1044. #if 0 /*to be done*/
  1045.     MaintainCursor();
  1046.     MaintainMenus();
  1047.     TEIdle(TEH);
  1048. #endif
  1049.     
  1050.     if (GetNextEvent(everyEvent, &macEvent) )
  1051.     {
  1052.         ut_PutString("RV|EventLoop: event.what",
  1053.                 event_types[macEvent.what]);
  1054.  
  1055.         switch (macEvent.what) 
  1056.         {
  1057.         case mouseDown:
  1058.         {
  1059.             int mousedown_code = FindWindow( macEvent.where, &whichWindow );
  1060.             ut_PutString("RV|MainLoop: FindWindow returns",
  1061.                  mousedown_types[mousedown_code]);
  1062.             ut_PrintHex("RV|MainLoop: mousedown in wptr",whichWindow);
  1063.             switch(mousedown_code) 
  1064.             {
  1065.             case inSysWindow:
  1066.             {
  1067.                 SystemClick( &macEvent, whichWindow );
  1068.                 return TRUE;
  1069.             } break;
  1070.             
  1071.             case inDesk:     
  1072.             {
  1073.                 SysBeep(10);
  1074.                 return TRUE;    
  1075.             } break;
  1076.             
  1077.             case inMenuBar: 
  1078.             {
  1079.                 long menu_selection = MenuSelect(macEvent.where);
  1080.                 int  menu_category  = HiWord(menu_selection);
  1081.                 int  menu_item      = LoWord(menu_selection);
  1082.                 
  1083.                 if( menu_category)
  1084.                 {
  1085. #ifdef DBG
  1086.                     if(ut_FilterMenuSelection(menu_selection))
  1087.                         return TRUE;
  1088. #endif
  1089.                     appEvent->cmd_category = menu_category;
  1090.                     appEvent->cmd_item     = menu_item; 
  1091.                     appEvent->event_type   = CMD_EVENT;
  1092.                     return FALSE;
  1093.                 }
  1094.                 else
  1095.                     return TRUE;
  1096.             } break;
  1097.             
  1098.             case inGoAway:
  1099.             {
  1100.                 if (vu_IsAppView((LONG) whichWindow)    
  1101.                     && TrackGoAway( whichWindow, macEvent.where) )
  1102.                 {
  1103.                     appEvent->event_type   = CLOSEVIEW_EVENT;
  1104.                     appEvent->canvas       = LoWord(((WindowPeek)whichWindow)->refCon);
  1105.                     appEvent->where        = macEvent.where;
  1106.                     return FALSE;
  1107.                 }
  1108.                 else
  1109.                     return TRUE;
  1110.             } break;
  1111.                 
  1112.             case inDrag:
  1113.             {
  1114.                 if (vu_IsAppView((LONG)whichWindow) )
  1115.                 {
  1116.                     appEvent->event_type   = MOVEVIEW_EVENT;
  1117.                     appEvent->canvas       = LoWord(((WindowPeek)whichWindow)->refCon);
  1118.                     appEvent->where        = macEvent.where;
  1119.                     return FALSE;
  1120.                 }
  1121.                 else
  1122.                     return TRUE;
  1123.                 } break;
  1124.                 
  1125.             case inContent:
  1126.             {
  1127.                 if (whichWindow != FrontWindow())
  1128.                 {
  1129.                     SelectWindow(whichWindow);
  1130.                     SetPort((GrafPtr)whichWindow);
  1131.                     return TRUE;
  1132.                 }
  1133.                 else if (vu_IsAppView((LONG)whichWindow) )
  1134.                 {
  1135.                     appEvent->event_type   = MOUSEDOWN_EVENT;
  1136.                     appEvent->canvas       = LoWord(((WindowPeek)whichWindow)->refCon);
  1137.                     appEvent->where        = macEvent.where;
  1138.                     return FALSE;
  1139.                 }
  1140.                 else 
  1141.                     return TRUE;
  1142.             } break;
  1143.  
  1144.             case inGrow:
  1145.             {
  1146.                 if (vu_IsAppView((LONG)whichWindow) )
  1147.                 {
  1148.                     appEvent->event_type   = RESIZEVIEW_EVENT;
  1149.                     appEvent->canvas       = LoWord(((WindowPeek)whichWindow)->refCon);
  1150.                     appEvent->where        = macEvent.where;
  1151.                     return FALSE;
  1152.                 }
  1153.                 else 
  1154.                     return TRUE;    
  1155.             } break;
  1156.                 
  1157.            } /* end switch on mousedown_code from FindWindow() */
  1158.             
  1159.         } break; /*end case mouseDown */
  1160.     
  1161.         case autoKey: 
  1162.             /*FALL THROUGH */
  1163.         case keyDown:                    
  1164.         {
  1165.             REG char    theChar = macEvent.message & charCodeMask;
  1166.                     
  1167.             if ((macEvent.modifiers & cmdKey) != 0) 
  1168.             {
  1169.                 long menu_selection = MenuKey( theChar );
  1170.                 int  menu_category  = HiWord(menu_selection);
  1171.                 int  menu_item      = LoWord(menu_selection);
  1172.                 if( menu_category)
  1173.                 {
  1174.                     appEvent->cmd_category = menu_category;
  1175.                     appEvent->cmd_item     = menu_item; 
  1176.                     appEvent->event_type   = CMD_EVENT;
  1177.                     return FALSE;
  1178.                 }
  1179.                 else
  1180.                     return TRUE;
  1181.             }
  1182.             else 
  1183.             {
  1184.                 appEvent->the_char        = theChar;
  1185.                 appEvent->event_type    = CHAR_EVENT;
  1186.                 return FALSE;
  1187.             }
  1188.         } break;
  1189.  
  1190.         case activateEvt:
  1191.         {
  1192.             if (vu_IsAppView((LONG)(macEvent.message)) )
  1193.             {
  1194.                 appEvent->event_type    = ACTIVATEVIEW_EVENT;
  1195.                 appEvent->canvas        = LoWord(((WindowPeek)(macEvent.message))->refCon);
  1196.                 return FALSE;
  1197.             }
  1198. #ifdef DBG
  1199.             else if(ut_IsDebugWindow((WindowPtr)(macEvent.message)) )
  1200.             {
  1201.                 ut_ActivateDebugWindow();
  1202.                 return TRUE;
  1203.             }
  1204. #endif
  1205.             else 
  1206.                 return TRUE;
  1207.         }    break;
  1208.         
  1209.         case updateEvt:
  1210.         {
  1211.             if (vu_IsAppView((LONG)(macEvent.message)) )
  1212.             {
  1213.                 appEvent->event_type    = UPDATEVIEW_EVENT;
  1214.                 appEvent->canvas        = LoWord(((WindowPeek)(macEvent.message))->refCon);
  1215.                 return FALSE;
  1216.             }
  1217.  
  1218. #ifdef DBG
  1219.             else if(ut_IsDebugWindow((WindowPtr)(macEvent.message)) )
  1220.             {
  1221.                 ut_UpdateDebugWindow();
  1222.                 return TRUE;
  1223.             }
  1224. #endif
  1225.             else
  1226.             {
  1227.                 BeginUpdate((WindowPtr)(macEvent.message));
  1228.                 EndUpdate((WindowPtr)(macEvent.message));
  1229.                 return TRUE;
  1230.             }
  1231.         } break;
  1232.         
  1233.         } /* end of case macEvent.what */
  1234.     } /* if */
  1235.     
  1236.     return TRUE;
  1237. }
  1238. #endif /*macintosh specific internal event loop*/
  1239.  
  1240.  
  1241. /****************************************************************
  1242.     MENU/COMMAND PROCESSING
  1243. ****************************************************************/    
  1244.  
  1245. #ifdef MAC  /*macintosh specific is here. See WINMAIN.c for MSWINDOWS */
  1246.  
  1247. #include "dispatch.h"
  1248.  
  1249. #include "MenuMgr.h"
  1250.  
  1251. LOCAL MenuHandle theMenuCategories[NUM_MENU_CATEGORIES];
  1252.  
  1253. PUBLIC BOOL env_InitMenus()
  1254. {
  1255.     int        i;
  1256.     
  1257.     /*this is optional check to see if we can access the resource file */
  1258.     OpenResFile("\pgenapp.rsrc"); 
  1259.                                     
  1260.     if (GetResource('MENU', R_ID_FILE_MENU)==0) 
  1261.     {
  1262.         env_FatalError("miniEdit.c: Can't open resource file.");
  1263.         /*call does not return*/
  1264.         return FALSE;
  1265.     }
  1266.     theMenuCategories[SYS_MENU] = NewMenu( R_ID_SYS_MENU, "\p\024" );
  1267.     AddResMenu( theMenuCategories[SYS_MENU], 'DRVR' );
  1268.     
  1269.     theMenuCategories[FILE_MENU] = GetMenu(R_ID_FILE_MENU);
  1270.     theMenuCategories[EDIT_MENU] = GetMenu(R_ID_EDIT_MENU);
  1271.     
  1272.     theMenuCategories[VIEW_MENU] = NewMenu(R_ID_VIEW_MENU, "\pView");
  1273.     AppendMenu(theMenuCategories[VIEW_MENU],"\pGraphics View");
  1274.     AppendMenu(theMenuCategories[VIEW_MENU],"\pText View");
  1275.  
  1276.     theMenuCategories[PALETTE_MENU] = NewMenu(R_ID_PALETTE_MENU,"\pPalette");
  1277.     AppendMenu(theMenuCategories[PALETTE_MENU],"\pSelection Tool");
  1278.     AppendMenu(theMenuCategories[PALETTE_MENU],"\pCreate Rect Tool");
  1279.  
  1280.     for ( i = 0; i < NUM_MENU_CATEGORIES; i++ ) 
  1281.         InsertMenu(theMenuCategories[i], 0) ;
  1282.  
  1283.     DrawMenuBar();
  1284.     return TRUE;
  1285. }
  1286.  
  1287. #else
  1288. PUBLIC BOOL env_InitMenus(){return TRUE;} /*ms-windows version*/
  1289. #endif
  1290.  
  1291. PUBLIC VOID env_DoSysMenu(menu_item)
  1292.     int menu_item;
  1293. {
  1294. #ifdef MAC
  1295.     Str255    name;
  1296.     
  1297.     GetItem(theMenuCategories[SYS_MENU], menu_item, &name);
  1298.     OpenDeskAcc( &name );
  1299.     vu_SetCurrentView();
  1300. #endif /*windows version not needed*/
  1301. }
  1302.  
  1303.  
  1304.  
  1305. /****************************************************************
  1306.     DEBUGGING
  1307. ****************************************************************/
  1308. #ifdef MAC
  1309. #include <stdio.h>
  1310. typedef char *va_list;
  1311. #define va_start(ap,v)        ap=(va_list)&v+sizeof(v)
  1312.  
  1313. #define SOME_RESOURCE_ID        1        /* ???? */
  1314.  
  1315. /* can't take an HCANVAS param because it might be wrong! */
  1316. void debug(mask)
  1317.     char *mask;
  1318. {
  1319.     char buf[255];
  1320.     va_list args;
  1321.     
  1322.     va_start(args, mask);
  1323.     vsprintf(buf, mask, args);
  1324.     ParamText(buf, 0L, 0L, 0L);
  1325.     StopAlert(SOME_RESOURCE_ID, 0L);
  1326. }
  1327. #else
  1328. #include <stdarg.h>
  1329.  
  1330. /* can't take an HCANVAS param because it might be wrong! */
  1331. VOID debug(mask)
  1332.     char *mask;
  1333. {
  1334.     char buf[255];
  1335.     va_list args;
  1336.     
  1337.     va_start(args, mask);
  1338.     vsprintf(buf, mask, args);
  1339.     MessageBox(GetActiveWindow(), buf, "Debug!", MB_OK);
  1340. }
  1341. #endif
  1342.  
  1343. #ifdef MAC
  1344. PUBLIC VOID memset(ptr,value,count)
  1345.     MEMPTR ptr;int value; int count;
  1346. {
  1347.     while(count--) *ptr++ = value;
  1348. }
  1349. #endif
  1350.